﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Speech.Synthesis;
using System.Speech;
using System.Text;
using System.Threading;

namespace CATLTempUpdate
{
    class SpeakVoiceClass
    {
        SpeechSynthesizer iSpeech = new SpeechSynthesizer();
        //public ConcurrentDictionary<string, AlarmSpeakMod> SpeakList = new ConcurrentDictionary<string, AlarmSpeakMod>();
        Thread SpeckThead;
        bool SpeakTag = true;

        public SpeakVoiceClass()
        {
            iSpeech.Volume = 100;
            iSpeech.Rate = 0;
            //SpeckThead = new Thread(SpeakFromDic);
            //SpeckThead.Start();
        }

        public void SpeakFromDic(string msg)
        {
            iSpeech.SelectVoice("Microsoft Anna");
            iSpeech.Speak(msg);
                
        }


        //public void SpeakAdd(ErrorCh erroCh)
        //{
        //    string stagekey = erroCh.chmodel.Column.ToString().PadLeft(2, '0') + erroCh.chmodel.Layer.ToString().PadLeft(2, '0');
        //    if (SpeakList.ContainsKey(stagekey))
        //    {
        //        if (SpeakList[stagekey].AlarmLevel <= erroCh.ErrorLevel)
        //        {
        //            SpeakList[stagekey].AlarmMsg = "第" + erroCh.chmodel.Column.ToString() + "机柜" +
        //                "第" + erroCh.chmodel.Layer.ToString() + "层因" + erroCh.Errormessage + "发生" + LevelStr(erroCh.ErrorLevel);
        //        }
        //    }
        //    else
        //    {
        //        AlarmSpeakMod asm = new AlarmSpeakMod();
        //        asm.chmodel = erroCh.chmodel;
        //        asm.AlarmLevel = erroCh.ErrorLevel;
        //        asm.AlarmMsg = "第" + erroCh.chmodel.Column.ToString() + "机柜" +
        //                "第" + erroCh.chmodel.Layer.ToString() + "层因" + erroCh.Errormessage + "发生" + LevelStr(erroCh.ErrorLevel);
        //        SpeakList.TryAdd(stagekey, asm);
        //    }
        //}

        //public void Remove(string col, string ilayer)
        //{
        //    AlarmSpeakMod asm = new AlarmSpeakMod();
        //    string stagekey = col.PadLeft(2, '0') + ilayer.PadLeft(2, '0');
        //    SpeakList.TryRemove(stagekey, out asm);
        //}

        private string LevelStr(int alarmlevel)
        {
            string istr = "";
            switch (alarmlevel)
            {
                case 1:
                    istr = "通道报警";
                    break;
                case 2:
                    istr = "架台报警";
                    break;
                case 3:
                    istr = "火灾报警";
                    break;
            }
            return istr;
        }

        //public void Clear()
        //{
        //    foreach (AlarmSpeakMod asm in SpeakList.Values)
        //    {
        //        string col = asm.chmodel.Column.ToString();
        //        int layer = asm.chmodel.Layer;
        //        JudgeWarn.VacuoSt.StagePlcAlarm(col, layer, 0);
        //    }
        //    SpeakList.Clear();
        //}

        //public void Remove(int col, int layer)
        //{
        //    string stagekey = col.ToString().PadLeft(2, '0') + layer.ToString().PadLeft(2, '0');
        //    JudgeWarn.VacuoSt.StagePlcAlarm(col.ToString(), layer, 0);
        //    AlarmSpeakMod asm = new AlarmSpeakMod();
        //    SpeakList.TryRemove(stagekey, out asm);
        //}

        public void Dipose()
        {
            SpeakTag = false;
            SpeckThead.Abort();
        }
    }
}